#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    void helper(TreeNode* root, int k, int& num, int& n)
    {
        if (root == nullptr) return;
        helper(root->left, k, num, n);
        if (n < k)
        {
            n++;

            num = root->val;
            cout << num;
        }
        helper(root->right, k, num, n);

    }
    int kthSmallest(TreeNode* root, int k) {
        int num = INT_MAX;
        int n = 0;
        helper(root, k, num, n);
        return num;
    }
};